package per.jdz.demo.controller;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import per.jdz.demo.config.FilePathConfigProperty;
import per.jdz.demo.domain.entity.OriginHouseData;
import per.jdz.demo.domain.entity.OriginLandData;
import per.jdz.demo.domain.vo.reponse.ApiResult;
import per.jdz.demo.readlistener.GenericReadListener;
import per.jdz.demo.service.OriginLandDataService;

import javax.annotation.Resource;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;

/**
 * @author Jdz
 * @date 2025/1/14
 */
@RestController
@Slf4j
@RequestMapping("/origin/land")
public class OriginLandDataController {
    // 用于保存当前批次的数据
    @Resource
    private FilePathConfigProperty filePathConfigProperty;
    @Resource
    private OriginLandDataService originLandDataService;

    @PostMapping("/insertData")
    public ApiResult insertData() {
        originLandDataService.insertData(originLandDataService::saveBatch);
        return ApiResult.success();
    }

    @GetMapping("/splitFile")
    public ApiResult splitFile() {
        String msg = originLandDataService.splitFile();
        return ApiResult.success(msg);
    }

    @GetMapping("/distinctData")
    public ApiResult distinctData() {
        log.info("开始去重");
        originLandDataService.distinctData();
        return ApiResult.success();
    }

    @GetMapping("/syncData")
    public ApiResult syncData() {
        log.info("开始更新数据");
        originLandDataService.syncData();
        return ApiResult.success();
    }

    @PostMapping("/addNewData")
    public ApiResult addNewData(@RequestBody List<OriginLandData> originLandDataList) {
//        originHouseDataService.saveBatch(originHouseDataList);
        log.info("爬取数据入库");
        System.out.println(originLandDataList);
        return ApiResult.success();
    }
}
